import { useStoreDict } from '@/store';
import { reactive, toRefs } from 'vue';
/**
 * @description: message
 */
export function useDict(enumTypes: any = []) {
  const storeDict: any = useStoreDict();
  if (!Array.isArray(enumTypes)) {
    enumTypes = [enumTypes];
  }
  const obj: any = {};
  for (let i = 0; i < enumTypes.length; i++) {
    const enumItem: any = enumTypes[i].key;
    obj[enumItem] = [];
    // obj[enumItem + '_ALL'] = [];
    obj[enumItem + '_OBJ'] = {};
  }
  const dictResult = reactive(obj);
  for (let i = 0; i < enumTypes.length; i++) {
    const enumItem: any = enumTypes[i].key;
    const dataType: any = enumTypes[i].type || 'number';
    console.log('dataType', dataType);

    storeDict.updateTargetDict(enumItem, dataType).then(() => {
      // dictResult[enumItem] = storeDict.dictEnum[enumItem];
      // dictResult[enumItem + '_ALL'] = storeDict.dictEnumAll[enumItem];
      dictResult[enumItem] = storeDict.dictEnumAll[enumItem];
      dictResult[enumItem + '_OBJ'] = storeDict.dictEnumObj[enumItem];
    });
  }
  return toRefs(dictResult);
}
/**
 * 实例，字典名称为'EQU_TYPE_LIST'的用法
 */
// let { EQU_TYPE_LIST, EQU_TYPE_LIST_ALL, EQU_TYPE_LIST_OBJ } = useDict([{
//   key: 'EQU_TYPE_LIST',
//   type: 'number'
// }])
